package com.example.cloudindex.web;

import com.example.cloudindex.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@RestController
public class IndexAction {

    @RequestMapping("/toIndex")
    String toIndex(){
        return "你好";
    }


    @Resource
    RestTemplate restTemplate;
    @RequestMapping("/getOrder")
    String toOrder(){
        String url="http://cloud-order/order";
        final String forObject = restTemplate.getForObject(url, String.class);
        return forObject;
    }

    @Resource
    IOrderAction iOrderAction;

    @GetMapping("toOrderByFeign")
    String toOrderByFeign(){
        return iOrderAction.order();
    }

    @RequestMapping("/toOrderUser")
    User toOrderUser(User user){
        return iOrderAction.user(user);

    }

    @RequestMapping("/toOrderAdd")
    int toOrderAdd(int a,int b){
        return iOrderAction.add(a, b);
    }

    @RequestMapping("/toOrderHello")
    String toOrderHello(String name){
        return iOrderAction.hello(name);
    }
}
